package com.crocodileQ.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * 文件名生成
 */
public class PathUtils {

    public static String generateFilePath(String fileName){
        //根据日期生成路径 2001/1/1
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        String datePath = sdf.format(new Date());
        //uuid作为文件名
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        //后缀和文件后缀一致
        int index = fileName.lastIndexOf(".");
        String fileType = fileName.substring(index);

        //2001/11/1test.jpg

        return new StringBuilder().append(datePath).append(uuid).append(fileType).toString();

    }
}
